﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CommonMvc.Common;
using CommonMvc.Controllers;
using CommonMvc.Models.CommonModels;
using CommonMvc.Models.Concreate;
using CommonMvc.Models.Home;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;

namespace CommonMvc.Areas.Sysmanager.Controllers
{
    public class DefaultController : BaseController
    {
        public DefaultController(DataContext context, IWorkContext workContext, IDistributedCache distributedCache)
          : base(context, workContext, distributedCache)//依赖注入得到实例  
        { }

        public IActionResult Index()
        {            
            return Content("sysmanager default index");
          
        }
        public IActionResult Login(HomeLogin LoginModel)
        {

            Person p = _dataBaseContext.Persons.ToList().Where(person => person.Name == LoginModel.Name).FirstOrDefault() as Person;
            if (p == null)
            {
                return JsonFailResult(null, "用户不存在,或账户密码错误");
            }
           
            User user = new User
            {
                UserId = p.Id,
                UserType = UserType.Sys,
                IsLogin = true
            };
            BaseLogin(user);
            return JsonSuccessResult(null, "登录成功");
        }
    }
}